package com.example.vehicleservice.controller;


import com.alibaba.fastjson.JSON;

import com.example.vehicleservice.bean.*;
import com.example.vehicleservice.service.NewCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName：NewCarController
 * @Author: Vvn
 * @Date: 2025/5/29 8:59
 * @Description: 必须描述类做什么事情, 实现什么功能
 */

@RestController
@RequestMapping("/NewCar")
public class NewCarController {


    @Autowired
    private NewCarService newCarService;


    @RequestMapping("/getCarRealtime")
    private String getCarRealtime() throws Exception {


        List<CarRealtime> carRealtimeList = newCarService.getCarRealtime();


        for (CarRealtime carRealtime : carRealtimeList) {

            System.out.println(carRealtime.toString());
        }

        if (carRealtimeList == null || carRealtimeList.isEmpty()) {
            return "[]";
        }

        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("车辆VIN", "vin"));
        name.add(new SugarOne("行程ID", "tripId"));
        name.add(new SugarOne("行程距离", "distance"));

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(carRealtimeList)
                + "\n" +
                "  }\n" +
                "}";
    }


    @RequestMapping("/getCarTry")
    private String getCarTry() throws Exception {


        List<carTry> carTryList = newCarService.getCarTry();
        if (carTryList == null || carTryList.isEmpty()) {
            return "[]";
        }

        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("车辆VIN", "vin"));
        name.add(new SugarOne("异常类型", "alarm_type"));

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(carTryList)
                + "\n" +
                "  }\n" +
                "}";
    }


    @RequestMapping("/getVehicleCount")
    private String getVehicleCount() throws Exception {


        List<VehicleCount> vehicleCountList = newCarService.getVehicleCount();
        if (vehicleCountList == null || vehicleCountList.isEmpty()) {
            return "[]";
        }

        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("开始时间", "window_start"));
        name.add(new SugarOne("车辆数", "vin_count"));

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(vehicleCountList)
                + "\n" +
                "  }\n" +
                "}";
    }


    @RequestMapping("/getVehicleDwsBatteryHealth")
    private String getVehicleDwsBatteryHealth() throws Exception {


        List<VehicleDwsBatteryHealth> vehicleCountList = newCarService.getVehicleDwsBatteryHealth();
        if (vehicleCountList == null || vehicleCountList.isEmpty()) {
            return "[]";
        }

        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("开始时间", "startTime"));
        name.add(new SugarOne("平均电池健康状态", "avgTemp"));

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(vehicleCountList)
                + "\n" +
                "  }\n" +
                "}";
    }


    @RequestMapping("/getVehicleGeohashVinCount")
    private String getVehicleGeohashVinCount() throws Exception {


        List<VehicleGeohashVinCount> VehicleGeohashVinCountList = newCarService.getVehicleGeohashVinCount();
        if (VehicleGeohashVinCountList == null || VehicleGeohashVinCountList.isEmpty()) {
            return "[]";
        }

        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("经纬度编码", "geoHash"));
        name.add(new SugarOne("分布次数", "vinCount"));

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(VehicleGeohashVinCountList)
                + "\n" +
                "  }\n" +
                "}";
    }


    @RequestMapping("/getVehicleStatus")
    private String getVehicleStatus() throws Exception {


        List<VehicleStatus> VehicleStatusList = newCarService.getVehicleStatus();
        if (VehicleStatusList == null || VehicleStatusList.isEmpty()) {
            return "[]";
        }


        ArrayList<SugarOne> name = new ArrayList<>();
        name.add(new SugarOne("车辆VIN", "vin"));
        name.add(new SugarOne("车速", "speed"));
        name.add(new SugarOne("电池电量", "batteryLevel"));
        name.add(new SugarOne("电池温度'", "batteryTemp"));
        name.add(new SugarOne("电机温度", "motorTemp"));
        name.add(new SugarOne("充电状态", "chargingStatus"));
        name.add(new SugarOne("瞬时能耗", "energyConsumption"));


        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"hitSugarSelf\": true,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"columns\": " +
                JSON.toJSONString(name)
                + ",\n" +
                "    \"rows\": " +
                JSON.toJSONString(VehicleStatusList)
                + "\n" +
                "  }\n" +
                "}";
    }
}
